package com.zp.system.controller;

import com.zp.common.core.controller.BaseController;
import com.zp.common.core.entity.R;
import com.zp.common.core.validate.AddGroup;
import com.zp.common.core.validate.EditGroup;
import com.zp.common.excel.utils.ExcelUtil;
import com.zp.common.log.annotation.Log;
import com.zp.common.log.enums.BusinessType;
import com.zp.common.myBatis.core.page.PageQuery;
import com.zp.common.myBatis.core.page.TableDataInfo;
import com.zp.system.entity.bo.DictVsClinicBo;
import com.zp.system.entity.vo.DictVsClinicVo;
import com.zp.system.service.IDictVsClinicService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 字典与诊疗项目对照控制器
 * 前端访问路由地址为:/system/dictVsClinic
 *
 * @author zhang peng
 * @ date 2024-03-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/dictVsClinic")
public class DictVsClinicController extends BaseController {

    private final IDictVsClinicService iDictVsClinicService;

    /**
     * 查询字典与诊疗项目对照列表 (分页)
     */
    @GetMapping("/selectPage")
    public TableDataInfo<DictVsClinicVo> selectPage(DictVsClinicBo bo, PageQuery pageQuery) {
        return iDictVsClinicService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询字典与诊疗项目对照列表 (不分页)
     */
    @GetMapping("/list")
    public R<List<DictVsClinicVo>> list(DictVsClinicBo bo) {
        List<DictVsClinicVo> list = iDictVsClinicService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 导出字典与诊疗项目对照列表
     */
    @Log(title = "字典与诊疗项目对照", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DictVsClinicBo bo, HttpServletResponse response) {
        List<DictVsClinicVo> list = iDictVsClinicService.queryList(bo);
        ExcelUtil.exportExcel(list, "字典与诊疗项目对照", DictVsClinicVo.class, response);
    }

    /**
     * 获取字典与诊疗项目对照详细信息
     *
     * @param baseDictId 主键
     */
    @GetMapping("/{baseDictId}")
    public R<DictVsClinicVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable String baseDictId) {
        return R.ok(iDictVsClinicService.queryById(baseDictId));
    }

    /**
     * 新增字典与诊疗项目对照
     */
    @Log(title = "字典与诊疗项目对照", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DictVsClinicBo bo) {
        return toAjax(iDictVsClinicService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改字典与诊疗项目对照
     */
    @Log(title = "字典与诊疗项目对照", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DictVsClinicBo bo) {
        return toAjax(iDictVsClinicService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除字典与诊疗项目对照
     *
     * @param baseDictIds 主键串
     */
    @Log(title = "字典与诊疗项目对照", businessType = BusinessType.DELETE)
    @DeleteMapping("/{baseDictIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable String[] baseDictIds) {
        return toAjax(iDictVsClinicService.deleteWithValidByIds(Arrays.asList(baseDictIds), true) ? 1 : 0);
    }
}
